/* 
 * File:   FreeList.h
 * Author: unshaikh
 *
 * Created on February 9, 2011, 1:02 PM
 */

#ifndef FREELIST_H
#define	FREELIST_H

#include "BlockLinkedList.h"
#include "BlockException.h"
#include "BlockGroupException.h"
#include "BlockGroup.h"
#include "Block.h"
#include "Disk.h"
#include <iostream>
#include <stdio.h>
class FreeList : public BlockLinkedList {
public:


    /**
     * This constructor generates a RAM object representing the free list
     * for the Disk.
     * @param fileName is name of a file previously used to create a Disk
     * object. I.e., the simulated disk should exist before this call, but
     * a Disk object representing it should not yet be open.
     * @param createFreeList should be true if a free list has not yet been
     * created for this Disk. This will create the free list (calls
     * CreateFreeList) for this BlockGroup. Otherwise, reads the starting and
     * ending block numbers for the free list from block 0. That is, set this
     * parameter to true to initialize the free list and loose all existing
     * data, and to false to use the existing free list.
     * @exeption BlockGroupException if there was a problem opening or
     * intializing the free list.
     */
    FreeList (const char *fileName, bool createFreeList);

    /**
     * Writes out the current start block of the free list to block 0, and
     * closes the Disk.
     * @return     true iff the Free List could be closed.
     */
    bool Close ();

    /**
     * Returns all blocks of the BlockLinkedList to the Free List.
     * @param bll  after this call, this BlockLinkedList has been deallocated.
     */
    void Return (BlockLinkedList *bll);

    /**
     * Spawn a new BlockGroup from the Free List.
     * The new BlockGroup has one block to start. This block is updated on disk
     * by this call.
     *
     * @return A new BlockGroup, or NULL if one could not be created.
     */
    BlockGroup* CreateNew ();


    ~FreeList();


    static void	Test ();

    /**
     * The default number of blocks for a Disk to be used with this class.
     */
    static const int DEFAULT_NUMBER_OF_BLOCKS = 100;
private:

};

#endif	/* FREELIST_H */

